//
//  BSNavigationController.m
//  baisibudejie
//
//  Created by 陈博文 on 15/12/18.
//  Copyright © 2015年 陈博文. All rights reserved.
//

#import "BSNavigationController.h"

@interface BSNavigationController ()<UIGestureRecognizerDelegate>

@end


@implementation BSNavigationController


//在显示之前进行设置
+(void)load{
//     BSFunc;
    UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
    
    // 设置导航条标题字体
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    // 字体
    attr[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20];
    
    [navBar setTitleTextAttributes:attr];
    
    [navBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
}



- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    // 不是根控制器才需要设置
    if (self.childViewControllers.count > 0) {
        // 不是根控制器
        //============设置导航栏隐藏=====================
        //在跳转之前进行隐藏
        viewController.hidesBottomBarWhenPushed = YES;
         //============设置导航栏隐藏=====================
        
        // 设置返回按钮
        // 设置返回按钮,左边按钮
        UIBarButtonItem *backItem = [UIBarButtonItem backItemWithImage:[UIImage imageNamed:@"navigationButtonReturn"] highImage:[UIImage imageNamed:@"navigationButtonReturnClick"] target:self action:@selector(back) norColor:[UIColor blackColor] highColor:[UIColor redColor] title:@"返回"];
        
        viewController.navigationItem.leftBarButtonItem = backItem;
    }
    
    // 这个方法才是真正跳转
    [super pushViewController:viewController animated:animated];
}


-(void)back{
    [self popViewControllerAnimated:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    //    UIScreenEdgePanGestureRecognizer
    // Do any additional setup after loading the view.
    // 只要触发这个Pan手势,就会调用self对象pan方法
    // 1.创建全屏手势
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
    
    // 控制手势什么时候触发
    pan.delegate = self;
    
    // 全屏滑动返回
    [self.view addGestureRecognizer:pan];
    
    // 2.禁止边缘手势--因为 pan 可以实现边缘滑动
    self.interactivePopGestureRecognizer.enabled = NO;
    
    // 实现滑动返回功能
    //     self.interactivePopGestureRecognizer.delegate = self;
    
    // bug:假死:程序一直运行,但是界面动不了.
    // 在根控制器的view,不需要滑动返回,
    
    // 全屏滑动返回
    // 研究下系统自带的返回手势
    //    NSLog(@"%@",self.interactivePopGestureRecognizer.delegate);
}

#pragma mark - UIGestureRecognizerDelegate
// 控制手势是否触发
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    
    // 根控制器的时候
    return self.childViewControllers.count != 1;
    
}




@end
